<template>
  <div>
    <el-dialog
      title="修改密码"
      :visible.sync="dialogFormVisible"
      width="600px"
      :close-on-click-modal="false"
      append-to-body
    >
    <!-- @paste.native.capture.prevent="handleFalse"
                @copy.native.capture.prevent="handleFalse"
                @cut.native.capture.prevent="handleFalse" -->
      <el-form ref="elForm" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="旧密码" prop="sPassword">
              <el-input
                v-model.trim="form.sPassword"
                type="password"
                placeholder="请输入旧密码"
                show-password
                @paste.native.capture.prevent="handleFalse"
                @copy.native.capture.prevent="handleFalse"
                @cut.native.capture.prevent="handleFalse"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="新密码" prop="newPassword">
              <el-input
                v-model.trim="form.newPassword"
                placeholder="请输入密码"
                type="password"
                show-password
                @paste.native.capture.prevent="handleFalse"
                @copy.native.capture.prevent="handleFalse"
                @cut.native.capture.prevent="handleFalse"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="确认密码" prop="secondNewPw">
              <el-input
                v-model.trim="form.secondNewPw"
                placeholder="请确认密码"
                type="password"
                show-password
                @paste.native.capture.prevent="handleFalse"
                @copy.native.capture.prevent="handleFalse"
                @cut.native.capture.prevent="handleFalse"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('elForm')"
          >确 定
        </el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "MvCloudgateTerminalChangePassword",
  data() {
    const validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.form.newPassword) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      dialogFormVisible: false,
      form: {
        sPassword: "",
        newPassword: "",
        secondNewPw: "",
      },
      rules: {
        sPassword: [
          { required: true, message: "旧密码不能为空", trigger: "blur" },
        ],
        newPassword: [
          { required: true, message: "新密码不能为空", trigger: "blur" },
          {
            pattern:
              /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&*])[A-Za-z0-9!@#$%^&*]{12,32}$/,
            message: "12-32位,同时包含数字、大小写字母、特殊符号",
            trigger: "blur",
          },
        ],
        secondNewPw: [
          { required: true, message: "确认密码不能为空", trigger: "blur" },
          { required: true, validator: validatePass2, trigger: "blur" },
        ],
      },
    };
  },

  mounted() {},

  methods: {
    handleFalse() {
      return false;
    },
    open() {
      this.dialogFormVisible = true;
    },
    submitForm() {
      this.$refs.elForm.validate((vadite) => {
        if (vadite) {
          // console.log(this.form);
          this.$emit("changePW", this.form);
        }
      });
    },
    cancel() {
      this.dialogFormVisible = false;
    },
  },
};
</script>

<style lang="scss" scoped></style>
